package com.tanhua.server.controller;

import cn.hutool.core.util.ObjectUtil;
import com.tanhua.server.service.ChuanYinService;
import com.tanhua.server.vo.ChuanYinVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/peachblossom")
public class ChuanYinController {
    @Autowired
    private ChuanYinService chuanYinService;

    @GetMapping
    public ResponseEntity<ChuanYinVo> AcceptSound() {
        try {
            ChuanYinVo chuanYinVo = chuanYinService.AcceptMessage();
            if (ObjectUtil.isNotEmpty(chuanYinVo)) {
                return ResponseEntity.ok(chuanYinVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

    }

    @PostMapping
    public ResponseEntity<ChuanYinVo> SendSound(@RequestParam("soundFile") MultipartFile soundFile) {
        try {
            chuanYinService.SendMessage(soundFile);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

    }


}

